'use strict';
var vk; // 全局vk实例
// 涉及的表名
const dbName = {
	test: "vk-test", // 测试表
};

var db = uniCloud.database(); // 全局数据库引用
var _ = db.command; // 数据库操作符
var $ = _.aggregate; // 聚合查询操作符
/**
 * 权限注意：访问以下链接查看
 * 文档地址：https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#内置权限
 */
var cloudObject = {
	isCloudObject: true, // 标记为云对象模式
	/**
	 * 请求前处理，主要用于调用方法之前进行预处理，一般用于拦截器、统一的身份验证、参数校验、定义全局对象等。
	 * 文档地址：https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#before-预处理
	 */
	_before: async function() {
		vk = this.vk; // 将vk定义为全局对象
		// let { customUtil, uniID, config, pubFun } = this.getUtil(); // 获取工具包
	},
	/**
	 * 请求后处理，主要用于处理本次调用方法的返回结果或者抛出的错误
	 * 文档地址：https://vkdoc.fsq.pub/client/uniCloud/cloudfunctions/cloudObject.html#after-后处理
	 */
	_after: async function(options) {
		let { err, res } = options;
		if (err) {
			return; // 如果方法抛出错误，直接return;不处理
		}
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.updategbsydlzttzxsgb 前端调用的url参数地址
	 */
	updategbsydlzttzxsgb: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		res.num = db.collection('gsxy-wx-dzxs')
		.where({dlzt:'1'})
		.update({dlzt:'0'})
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.updategbsydlzttzxsdk 前端调用的url参数地址
	 */
	updategbsydlzttzxsdk: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		res.num = db.collection('gsxy-wx-dzxs')
		.where({dlzt:'0'})
		.update({dlzt:'1'})
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.updategbsydlzttzxsmx 前端调用的url参数地址
	 */
	updategbsydlzttzxsmx: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);gsxy-wx-tzxs
		//res.num = db.collection('gsxy-wx-dzxs') gsxy-wx-createabill
		// res.num = db.collection('gsxy-wx-createabill')
		// .where({description:'tzxs2'})
		// .update({type:'tzxs'})
		// res.num = db.collection('gsxy-wx-tzxs')
		// .where({jfzt:'1'})
		// .update({dlzt:'0'})
		res.num = db.collection('gsxy-wx-tzxs')
		.where({dlzt:'1'})
		.update({bz:'请使用台式电脑登录网址：http://www.hngsxy.com/pages/anon/xueyuan/wldchaxun.html，来校前请自行打印五联单，凭此单办理报到入学手续，如有疑问请致电：15211848126，周老师.'})
		// 业务逻辑结束-----------------------------------------------------------tzxs2
		return res;
	},
	/**
	 * 批量审核新媒体任务函数 
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.updatePlWxryWzLists 前端调用的url参数地址
	 */
	updatePlWxryWzLists: async function(data) {
		//let { uid } = this.getClientInfo(); // 获取客户端信息
		//let userInfo = await this.getUserInfo(); // 获取当前登录的用户信息s
		//console.log("请求参数", data);
		
		// 业务逻辑开始-----------------------------------------------------------
		let res = { code: 0, msg: '' };
		let {_ids,dlzt} = data;
		// 参数非空检测
		if (vk.pubfn.isNullOne(_ids)) {
			return { code: -1, msg: '参数错误' };
		}

		// 返回被修改的记录条数
		res.num = await vk.baseDao.update({
		  dbName:"gsxy-wx-dzxs", // 表名
		  whereJson:{ // 条件
			_id:_.in(_ids)
		  },
		  dataJson:{ // 需要修改的数据
			dlzt:dlzt
		  }
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 批量审核新媒体任务函数 
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.deletePlWxryWzListssd 前端调用的url参数地址
	 */
	deletePlWxryWzListssd: async function(data) {
		//let { uid } = this.getClientInfo(); // 获取客户端信息
		//let userInfo = await this.getUserInfo(); // 获取当前登录的用户信息s
		//console.log("请求参数", data);
		
		// 业务逻辑开始-----------------------------------------------------------
		let res = { code: 0, msg: '' };
		//let {_ids} = data;
		let _ids = [
		'431124200412050068',
		'431124200502170039',
		'43112420050222747X',
		'431124200512098421',
		'430223200508108373',
		'433127200408260119',
		'430426200505040182',
		'430426200503180026',
		'431121200507220374',
		'430426200511300411',
		'430426200512270429',
		'430426200502130246',
		'430426200510080592',
		'430581200505106516',
		'43052520050901727X',
		'430521200507149441',
		'431223200405260170',
		'431121200502040024',
		'43112120060507004X',
		'431121200506090141',
		'431121200501160307',
		'431121200603170282',
		'431121200505290272',
		'430527200503048115',
		'430523200502166632',
		'430981200411132811',
		'431321200609070283',
		'431321200504050497',
		'430424200506130216',
		'430424200604120097',
		'430421200601290649',
		'430421200605030406',
		'43042120060129018X',
		'431122200504090080',
		'431103200506100255',
		'431103200508190071',
		'431026200607100085',
		'431227200505100065',
		'431226200603030084',
		'431227200505170020',
		'43102320040408483X',
		'431023200502080058',
		'431023200604126547',
		'431003200501150944',
		'431126200505060030',
		'431126200511280339',
		'431126200409250141',
		'431126200507040076',
		'430124200503196264',
		'430523200509124347',
		'430124200510080825',
		'430281200601240241',
		'430124200504083317',
		'430822200510075116',
		'431122200503120081',
		'431382200509220339',
		'431382200408230183',
		'431382200508080362',
		'430522200511029211',
		'431322200511100591',
		'431322200507010454',
		'431322200509170144',
		'431322200606060318',
		'431322200410030328',
		'431322200503080324',
		'431102200509200167',
		'431102200601260234',
		'431102200503180222',
		'431102200506150248',
		'431022200506092252',
		'431022200512160100',
		'431022200504212820',
		'430482200508050045',
		'430482200511270313',
		'430482200507120232',
		'430482200512290025',
		'430482200409090404',
		'430521200506020013',
		'431302200405070012',
		'430381200506150139',
		'431382200509150684',
		'431224200510250325',
		'511325200505151447',
		'430424200510160143',
		'430602200408150136',
		'511621200410020410',
		'430626200510260172',
		'430624200601050047',
		'431225200408250114',
		'430422200509130147',
		'431281200501250064',
		'430626200512220027',
		'430421200508010120',
		'430407200512100017',
		'431221200507150084',
		'430581200510240760',
		'430408200601160085',
		'430422200505190134',
		'430422200611130274',
		'430702200510130022',
		'430721200508280098',
		'430721200509010022',
		'431025200509261225',
		'43042620030309908X',
		'430224200506280176'
		]
		// 参数非空检测
		if (vk.pubfn.isNullOne(_ids)) {
			return { code: -1, msg: '参数错误' };
		}

		//1.批量删除
		// 返回被删除的记录条数
		res.num = await vk.baseDao.del({
		  dbName:"gsxy-wx-dzxs",
		  whereJson:{
			zjhm:_.in(_ids)
		  }
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 批量审核新媒体任务函数 
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.deletePlWxryWzLists 前端调用的url参数地址
	 */
	deletePlWxryWzLists: async function(data) {
		//let { uid } = this.getClientInfo(); // 获取客户端信息
		//let userInfo = await this.getUserInfo(); // 获取当前登录的用户信息s
		//console.log("请求参数", data);
		
		// 业务逻辑开始-----------------------------------------------------------
		let res = { code: 0, msg: '' };
		let {_ids} = data;
		// 参数非空检测
		if (vk.pubfn.isNullOne(_ids)) {
			return { code: -1, msg: '参数错误' };
		}

		//1.批量删除
		// 返回被删除的记录条数
		res.num = await vk.baseDao.del({
		  dbName:"gsxy-wx-dzxs",
		  whereJson:{
			_id:_.in(_ids)
		  }
		});

		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.deleteWxryWzListOne 前端调用的url参数地址
	 */
	deleteWxryWzListOne: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		let dbName = "gsxy-wx-dzxs";
		// 业务逻辑开始-----------------------------------------------------------
		// 这里id不传默认设置成"___" 是为了防止因未传_id导致误删所有数据.
		let { _id } = data;
		if(vk.pubfn.isNull(_id)){
			return { code : -1, msg : 'id不能为空' };
		}
		res.num = await vk.baseDao.deleteById({
			dbName,
			id:_id
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.updateWxryWzListOne 前端调用的url参数地址
	 */
	updateWxryWzListOne: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		let dbName = "gsxy-wx-dzxs";
		let updateId = data._id
		Reflect.deleteProperty(data,'_id')
		// 此处应该还需要判断下mobile和username是否已存在等参数校验逻辑和
		//let register_date = new Date().getTime();
		res.newInfo = await vk.baseDao.updateById({
		  dbName:dbName,
		  id:updateId,
		  dataJson:{
		    ...data
		  }
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.addWxryWzListOne 前端调用的url参数地址
	 */
	addWxryWzListOne: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		res.id = await vk.baseDao.add({
		  dbName:"gsxy-wx-dzxs",// 表名
		  dataJson:{ // 需要新增的数据 json格式
			...data
		  }
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/zsc/kh/gsxy-wx-dzxs-obj.getWxryWzListList 前端调用的url参数地址 
	 */
	getWxryWzListList: async function(data) {
		let { uid, filterResponse, originalParam } = this.getClientInfo(); // 获取客户端信息
		let res = { code: 0, msg: '' };
		// 业务逻辑开始-----------------------------------------------------------
		//console.log("请求参数", data);
		let dbName = "gsxy-wx-dzxs";
		res = await vk.baseDao.getTableData({
		  dbName,
		  data
		});
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 获取列表
	 * @url admin/gsxy/demoobj.getList 前端调用的url参数地址
	 */
	getList: async function(data) {
		let res = { code: 0, msg: '' };
		let { uid } = this.getClientInfo(); // 获取客户端信息
		// 业务逻辑开始-----------------------------------------------------------
		
	
		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
	/**
	 * 模板函数
	 * @url admin/gsxy/demoobj.test 前端调用的url参数地址
	 */
	test: async function(data) {
		let res = { code: 0, msg: '' };
		let { uid } = this.getClientInfo(); // 获取客户端信息
		// 业务逻辑开始-----------------------------------------------------------


		// 业务逻辑结束-----------------------------------------------------------
		return res;
	},
};

module.exports = cloudObject;
